<!--# layout("/common/layout.html",{"jsBase":"/js/crm/crmQuestion/"}){ -->

<form class="layui-form layui-form-pane" id="addForm"  lay-filter="editform">
    <input type="hidden" name="id" id="id">

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">问题描述</label>
                <div class="layui-input-block" style="width:600px">
                    <textarea name="question" id="question" placeholder="请输入" class="layui-textarea" lay-verify="required"></textarea>
                </div>
            </div>

        </div><!--form item-->
    </div><!--row-->
    <div class="layui-row">
        <div class="layui-form-item">
            <label class="layui-form-label">平台</label>
            <div class="layui-input-inline">
                <select  name="come" selectValue="" promtion="请选择" lay-filter="come">
                    <option value="">请选择</option>
                    <option value="1">pc</option>
                    <option value="2">h5</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-inline">
                <select  name="type" id="type" selectValue="" promtion="请选择" lay-search>
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">

            <div class="layui-inline">
            <label class="layui-form-label">是否可用</label>
				<div class="layui-input-inline">
                    <select style="width:40%"  name="status" selectValue="" promtion="请选择" lay-search>
                        <option value="">请选择</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
				</div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">回答内容</label>
                <div class="layui-input-block" style="width:600px;z-index: 888">
                    <div id="content" ></div>
                    <input type="hidden" name="answer" id="answer"/>
                </div>
            </div>
        </div>
    </div>
    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.all.js"></script>
<script>
    var ue = UE.getEditor('content',{
        toolbars: [["undo", "redo",
            "|", "fontsize", "forecolor", "bold", "italic", "underline",
            "|", "justifyleft", "justifycenter", "justifyright", "justifyjustify", "lineheight",
            "|", "directionalityltr", "directionalityrtl", "indent",
            "|", "backcolor", "autotypeset", "spechars", "source",
            "|", "searchreplace", "simpleupload", "|", "fullscreen","mobile"]],
        serverUrl: "${ctxPath}/crm/crmQuestion/config",
        autoHeightEnabled: false,
        elementPathEnabled : false,　　//是否启用元素路径，默认是true显示
        wordCount:false,          //是否开启字数统计
        initialFrameHeight:300
    });
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadvideo') {
            console.log("upload");
            return '${ctxPath}/orgLecture/orgLecture/upload.json';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','crmQuestionApi'], function(exports) {
    var form = layui.form;
    var crmQuestionApi = layui.crmQuestionApi;
    var index = layui.index;
    var isNew = true;
    <!--# if(!(isEmpty(crmQuestionJson))){  -->
    isNew = false;
    <!--# } -->
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();
                $("#answer").val(ue.getContent());
                form.on('submit(form)', function(){
                    crmQuestionApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    <!--# if(!(isEmpty(crmQuestionJson))){  -->
        var formJson = ${crmQuestionJson};
        form.val("editform",formJson);
        ue.setContent(formJson.answer);
        getTypes(formJson.type);
    <!--# } -->
    form.on('select(come)', function(data){
        console.log(data)
        getTypes(data.value);
    });

    function getTypes(come) {
        $.ajax({
            type: 'POST',
            url: "${ctxPath}/crm/crmQuestion/getTypes.json",
            data: {
                come:come
            },
            dataType:'json',
            success: function(data){
                $("#type").html("");
                var option1 = $("<option>").val("").text("请选择");
                $("#type").append(option1);
                $.each(data, function(key, val) {
                    var option1 ;
                    if(val.typeId == "${crmQuestion.type}"){
                        option1 = $("<option selected>").val(val.typeId).text(val.typeName);
                    }else{
                        option1 = $("<option>").val(val.typeId).text(val.typeName);
                    }
                    $("#type").append(option1);
                });
                form.render('select');

            }
        });
    }

});
</script>
